﻿using LightContracts;
using NUnit.Framework;

namespace LightContractsTests
{
    [TestFixture]
    public class ChecksTest
    {
        [Test]
        public void ChecksTrue()
        {
            Checks.That(true, "desc");
        }

        [Test]
        public void ChecksIsNotNullTrue()
        {
            Checks.IsNotNull(new object(), "name");
        }

        [Test]
        public void ChecksFalse()
        {
            try
            {
                Checks.That(false, "desc");
                Assert.Fail("This code should not be reached.");
            }
            catch (AssertException exception)
            {
                Assert.AreEqual("Condition failed. The expectation was 'desc', but this is false.", exception.Message);
            }
        }

        [Test]
        public void ChecksFalseWithNamedMethod()
        {
            try
            {
            	Checks.That(IsInit);
                Assert.Fail("This code should not be reached.");
            }
            catch(AssertException exception)
            {
                Assert.AreEqual("Condition failed. The expectation was 'IsInit', but this is false.", exception.Message);
            }
        }

        private bool IsInit()
        {
        	return false;	
        }

        
        [Test]
        public void ChecksFalseWithAnonymousMethod()
        {
            try
            {
            	Checks.That(delegate(){return false;});
                Assert.Fail("This code should not be reached.");
            }
            catch(AssertException exception)
            {
                Assert.AreEqual("Condition failed. The expectation was 'anonymous function delivers true', but this is false.", exception.Message);
            }
        }

        [Test]
        public void ChecksFalseWithLambdaExpression()
        {
            try
            {
            	Checks.That(()=> false);
                Assert.Fail("This code should not be reached.");
            }
            catch(AssertException exception)
            {
                Assert.AreEqual("Condition failed. The expectation was 'anonymous function delivers true', but this is false.", exception.Message);
            }
        }

        
        
        
        [Test]
        public void ChecksIsNotNullFalse()
        {
            try
            {
                Checks.IsNotNull(null, "name");
                Assert.Fail("This code should not be reached.");
            }
            catch (AssertException exception)
            {
                Assert.AreEqual("Condition failed. The expectation was 'name is not null', but this is false.", exception.Message);
            }
        }
    }
}
